<?php
if (isset($_POST['op']) && !empty($_POST['op']) ){
    include 'config.php';
    $openid=$_POST['op'];
    $skey=$_POST['skey'];
    $tid=(int)$_POST['id'];
    $pid=(int)$_POST['pid'] -1;
    $ziduan='t'.$pid;
    if ('null' == $openid){
        exit;
    }
    $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
    if (!$mysqli->set_charset("utf8")) {}
    $query=$mysqli->query("SELECT id FROM q1 where openid='".$openid."' and skey='".$skey."' limit 0,1 ");
    if($query->num_rows>0){
        $getQ=$query->fetch_assoc();
        $getId=$getQ['id'];
        $sql="update q1 set ".$ziduan."='".$tid."' where id='".$getId."' ";
        $mysqli->query($sql);
    }else{
        $sql="insert into q1(skey,".$ziduan.",openid,createtime) values('".$skey."','".$tid."','".$openid."','".date("Y-m-d H:i:s")."')  ";
        $mysqli->query($sql);
    }
    $mysqli->close();
    echo 200;
}

